
*12345678901234567890123456789012345678901234567890123456789012345678901234567890
capture log close
clear all
set more off

*	************************************************************************
* 	File-Name: 	Aklinetal_Jharkhand_Replication.do
*	Date:  		05/27/2021
*	Authors: 	Michaël Aklin, Brian Blankenship, Vagisha Nandan, Johannes 
*				Urpelainen
*	Data Used:  Aklinetal_Jharkhand_Data.dta
*	Purpose:   	.do file to conduct the analysis for:
*	
*					"The Great Equalizer: Inequality in Tribal Energy Access and 
*					Policies to Address It", Energy Research & Social Sciences
*	************************************************************************


*	************************************************************************
*	0. Data
*	************************************************************************

use "Aklinetal_Jharkhand_Data.dta", clear


*	************************************************************************
*	1. Decriptive statistics
*	************************************************************************

*	************************************************************************
*	Table 1
*	************************************************************************

estpost tabstat q_73 q_74 watt_total index_appliances saubhagya logexpenditure age female [aweight=survey_weights]	///
	,	/// 
	by(q_22)	///
	statistics(mean p50 sd min max count) columns(statistics) 
esttab using "./Manuscript_base/Tables/SummaryStats_Combined.tex", ///
	cells("mean(label(Mean) fmt(2)) p50(label(Median) fmt(1)) sd(label(S.D.) fmt(1)) min(label(Min.) fmt(1)) max(label(Max) fmt(1)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs	///
	substitute(m$ m\\$)	
eststo clear


*	************************************************************************
*	Table 2
*	************************************************************************

preserve
label var q_73 "Electricity (from any source)"
label var q_74 "Hours of electricity per day"

label define tempq_22 1 "Scheduled Castes" 2 "Scheduled Tribes" 3 "General population" 4 "Other Backward Class"
label values q_22 tempq_22

estpost summarize v2_q_79_1 v2_q_79_2 v2_q_79_3 v2_q_79_4 v2_q_79_anybulb v2_q_79_5 v2_q_79_6 ///
	v2_q_79_7 v2_q_79_8 v2_q_79_9 v2_q_79_10 v2_q_79_11 v2_q_79_12 v2_q_79_13 v2_q_79_14
esttab using "./Manuscript_base/Tables/SummaryStats_appliances.tex", ///
	cells("mean(label(Mean) fmt(2)) count(label(Obs.) fmt(0))") ///
	nonumber label replace noobs	///
	substitute(m$ m\\$)	
eststo clear

*	Table 3
estpost tabulate q_73 q_22 [aweight=survey_weights]
esttab using "./Manuscript_base/Tables/tab_caste_elec.tex"	///
	, cell(colpct(fmt(1))) unstack noobs replace varlabels(`e(labels)') 
eststo clear
restore



*	************************************************************************
*	2. Analysis
*	************************************************************************

*	************************************************************************
*	Table 4: Tribe vs. other castes (village FE)
*	************************************************************************

*	xtset-ing the data
xtset villagecode

* Elec
eststo: xtreg q_73 ib3.q_22 [pweight=survey_weights], fe cluster(villagecode)
	quiet sum q_73 if e(sample) == 1
	estadd scalar outcome_mean=`r(mean)'
	estadd scalar outcome_sd=`r(sd)'
	estadd local fixed "$\checkmark$", replace
eststo: xtreg q_73 ib3.q_22 logexpenditure age female i.q_20 [pweight=survey_weights], fe cluster(villagecode)
	estadd local fixed "$\checkmark$", replace
eststo: reg q_73 ib3.q_22 logexpenditure age female i.q_20 i.districtcode [pweight=survey_weights], cluster(villagecode)
	estadd local fixed_dist "$\checkmark$", replace

eststo: xtreg q_74 ib3.q_22 [pweight=survey_weights], fe cluster(villagecode)
	quiet sum q_74 if e(sample) == 1
	estadd scalar outcome_mean=`r(mean)'
	estadd scalar outcome_sd=`r(sd)'
	estadd local fixed "$\checkmark$", replace
eststo: xtreg q_74 ib3.q_22 logexpenditure age female i.q_20 [pweight=survey_weights], fe cluster(villagecode)
	estadd local fixed "$\checkmark$", replace
eststo: reg q_74 ib3.q_22 logexpenditure age female i.q_20 i.districtcode [pweight=survey_weights], cluster(villagecode)
	estadd local fixed_dist "$\checkmark$", replace

eststo: xtreg watt_total ib3.q_22 [pweight=survey_weights], fe cluster(villagecode)
	quiet sum watt_total if e(sample) == 1
	estadd scalar outcome_mean=`r(mean)'
	estadd scalar outcome_sd=`r(sd)'
	estadd local fixed "$\checkmark$", replace
eststo: xtreg watt_total ib3.q_22 logexpenditure age female i.q_20 [pweight=survey_weights], fe cluster(villagecode)
	estadd local fixed "$\checkmark$", replace
eststo: reg watt_total ib3.q_22 logexpenditure age female i.q_20 i.districtcode [pweight=survey_weights], cluster(villagecode)
	estadd local fixed_dist "$\checkmark$", replace

eststo: xtreg saubhagya ib3.q_22 [pweight=survey_weights], fe cluster(villagecode)
	quiet sum saubhagya if e(sample) == 1
	estadd scalar outcome_mean=`r(mean)'
	estadd scalar outcome_sd=`r(sd)'
	estadd local fixed "$\checkmark$", replace
eststo: xtreg saubhagya ib3.q_22 logexpenditure age female i.q_20 [pweight=survey_weights], fe cluster(villagecode)
	estadd local fixed "$\checkmark$", replace
eststo: reg saubhagya ib3.q_22 logexpenditure age female i.q_20 i.districtcode [pweight=survey_weights], cluster(villagecode)
	estadd local fixed_dist "$\checkmark$", replace

esttab using "./Manuscript_base/Tables/reg_various_hhfe.tex"	///
	,  booktabs label replace ///
 	nodepvars se(2) b(2) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	compress nogaps ///
	stats(fixed fixed_dist N N_clust r2 outcome_mean outcome_sd, fmt(0 0 0 0 2 2 2) ///
    labels("Village FE" "District FE" "Observations" "\# Villages" "$ R^2$" "Mean of DV" "SD of DV")) ///
	mgroups("Electricity \{0,1\}" "Hours of electricity [0,24]" "Appliances Wattage" "Saubhagya \{0,1\}", pattern(1 0 0 1 0 0 1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	indicate("Expenditure (log) = logexpenditure" "Age = age" "Gender=female" "Education = *q_20*", label($\checkmark$ ))		///
	noconstant nonotes nomtitles nobaselevels drop(*districtcode* *_cons*)
eststo clear


*	************************************************************************
*	Table 5: Variation among tribes
*	************************************************************************

* Elec
eststo: reg q_73 ib1.tribe_main_num [pweight=survey_weights], cluster(villagecode)
	quiet sum q_73 if e(sample) == 1
	estadd scalar outcome_mean=`r(mean)'
eststo: reg q_73 ib1.tribe_main_num logexpenditure age female i.q_20 i.districtcode [pweight=survey_weights], cluster(villagecode)

* Hours
eststo: reg q_74 ib1.tribe_main_num [pweight=survey_weights], cluster(villagecode)
	quiet sum q_74 if e(sample) == 1
	estadd scalar outcome_mean=`r(mean)'
eststo: reg q_74 ib1.tribe_main_num logexpenditure age female i.q_20 i.districtcode [pweight=survey_weights], cluster(villagecode)

* Appliances
eststo: reg watt_total ib1.tribe_main_num [pweight=survey_weights], cluster(villagecode)
	quiet sum watt_total if e(sample) == 1
	estadd scalar outcome_mean=`r(mean)'
eststo: reg watt_total ib1.tribe_main_num logexpenditure age female i.q_20 i.districtcode [pweight=survey_weights], cluster(villagecode)

* Saubhagya
eststo: reg saubhagya ib1.tribe_main_num [pweight=survey_weights], cluster(villagecode)
	quiet sum saubhagya if e(sample) == 1
	estadd scalar outcome_mean=`r(mean)'
eststo: reg saubhagya ib1.tribe_main_num logexpenditure age female i.q_20 i.districtcode [pweight=survey_weights], cluster(villagecode)

esttab using "./Manuscript_base/Tables/reg_various_tribes_short.tex"	///
	,  booktabs label replace ///
 	nodepvars se(2) b(2) ///
	star(* 0.10 ** 0.05 *** 0.01) ///
	compress nogaps ///
	stats( N N_clust r2 outcome_mean, fmt(0 0 2 2 ) ///
    labels("Observations" "\# Villages" "$ R^2$" "Mean of DV")) ///
	mgroups("Electricity \{0,1\}" "Hours of electricity [0,24]" "Appliances Wattage" "Saubhagya \{0,1\}", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))	///
	indicate("Expenditure (log) = logexpenditure" "Age = age" "Gender=female" "Education = *q_20*" "District FE = *districtcode*", label($\checkmark$ ))		///
	noconstant nonotes nomtitles nobaselevels
eststo clear



*	************************************************************************
*	3. Figure
*	************************************************************************

*	************************************************************************
*	Figure 1: map done in R
*	************************************************************************


*	************************************************************************
*	Figure 2: Distribution of tribal respondents by village
*	************************************************************************

graph bar tribe_dummies3 tribe_dummies1 tribe_dummies2 tribe_dummies4 tribe_dummies6 tribe_dummies5	///
	, 	///
	over(Village_name_cal, sort(1) lab(nolab)) stack ///
	ytitle("Proportion of population by tribal status")	///
	legend(position(6) row(1) label(1 "Non-tribe") label(2 "Ho") label(3 "Munda") label(4 "Oraon") label(5 "Santhali") label(6 "Other tribe"))
graph export "./Manuscript_base/Figures/bar_dist_tribes.pdf", replace as(pdf)

*	************************************************************************
*	Figure 3
*	************************************************************************

tw (kdensity q_74 if q_22 == 1)	///
	(kdensity q_74 if q_22 == 2)	///
	(kdensity q_74 if q_22 == 3)	///
	(kdensity q_74 if q_22 == 4)	///	
		, ///
		ytitle("Density")	///
		xtitle("Hours of electricity per day")	///
		legend(label( 1 "SC") label(2 "ST") label(3 "General") label(4 "OBC") position(6) row(1))
graph export "./Manuscript_base/Figures/hist_hours_caste.pdf", replace as(pdf)


*	************************************************************************
*	Figure 4: Appliance ownership
*	************************************************************************

preserve
	
quiet tab q_22, gen(q22cat)
label var q22cat1 "SC"
label var q22cat2 "ST"
label var q22cat3 "General"
label var q22cat4 "Other Backward Class"

eststo m1: reg v2_q_79_1 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode) 
eststo m2: reg v2_q_79_2 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode) 
eststo m3: reg v2_q_79_3 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode)  
eststo m4: reg v2_q_79_4 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode)  
eststo m5: reg v2_q_79_5 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode)  
eststo m6: reg v2_q_79_6 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode)  
eststo m7: reg v2_q_79_7 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode)  
eststo m8: reg v2_q_79_8 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode)  
eststo m9: reg v2_q_79_9 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode) 
eststo m10: reg v2_q_79_10 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode) 
eststo m11: reg v2_q_79_11 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode) 
eststo m12: reg v2_q_79_12 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode) 
eststo m13: reg v2_q_79_13 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode) 
eststo m14: reg v2_q_79_14 q22cat1 q22cat2 q22cat4 i.districtcode [pweight=survey_weights], cluster(villagecode) 

coefplot (m1 \ m2 \ m3 \ m4 \ m5 \ m6 \ m7 \ m8 \ m9 \ m10 \ m11 /// 
	\ m12 \ m13 \ m14 )	///
		, 	///
		drop(_cons) aseq swapnames ///
		coeflabels(m1 = "Incandescent bulb" ///
			   m2 = "CFL" ///
			   m3 = "LED" /// 
			   m4 = "Tube" /// 
			   m5 = "Fans" /// 
			   m6 = "Irons" /// 
			   m7 = "Fridges" ///
			   m8 = "TVs" /// 
			   m9 = "Radios" ///
			   m10 = "Cooler" /// 
			   m11 = "Washing machine" /// 
			   m12 = "Stoves" /// 
			   m13 = "Inverters" ///
			   m14 = "Elec. pumps")	///
		xline(0) sort keep(q22cat2)	///
		xtitle("Probability of ST owning an appliance compared to general population")
graph export "./Manuscript_base/Figures/coef_appliances.pdf", replace as(pdf)
eststo clear

restore

*	************************************************************************
*	Figure 5: Electrification by tribe
*	************************************************************************

reg q_73 ibn.tribe_main_num [pweight=survey_weights], cluster(villagecode) noc
coefplot		///
	,	/// 
	drop(_cons) order(1.tribe_main_num 4.tribe_main_num 7.tribe_main_num  . ///	
		3.tribe_main_num 5.tribe_main_num 8.tribe_main_num)	///
	xtitle("Proportion electrified")
graph export "./Manuscript_base/Figures/coefplot_elec_tribe.pdf", replace as(pdf)

*	************************************************************************
*	Figure 6: Saubhagya by tribe
*	************************************************************************

reg saubhagya ibn.tribe_main_num [pweight=survey_weights], cluster(villagecode) noc
coefplot		///
	,	/// 
	drop(_cons) order( 1.tribe_main_num 4.tribe_main_num 7.tribe_main_num  . 	///
		2.tribe_main_num 6.tribe_main_num 8.tribe_main_num)	///
	xtitle("Proportion who benefited from Saubhagya")
graph export "./Manuscript_base/Figures/coefplot_saubhagya_tribe.pdf", replace as(pdf)





